package com.example.demo.entity;

import com.example.demo.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.quartz.CronExpression;

import java.text.ParseException;
import java.util.Date;

/**
 * 定时任务调度表 sys_job
 * 
 * @author ruoyi
 */
public class SysJob extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 任务ID */

    private Long jobId;

    /** 任务名称 */

    private String jobName;

    /** 任务组名 */

    private String jobGroup;

    /** 调用目标字符串 */

    private String invokeTarget;

    /** cron执行表达式 */

    private String cronExpression;

    /** cron计划策略 */

    private String misfirePolicy = "0";

    /** 是否并发执行（0允许 1禁止） */

    private String concurrent;

    /** 任务状态（0正常 1暂停） */

    private String status;

    public Long getJobId()
    {
        return jobId;
    }

    public void setJobId(Long jobId)
    {
        this.jobId = jobId;
    }


    public String getJobName()
    {
        return jobName;
    }

    public void setJobName(String jobName)
    {
        this.jobName = jobName;
    }

    public String getJobGroup()
    {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup)
    {
        this.jobGroup = jobGroup;
    }


    public String getInvokeTarget()
    {
        return invokeTarget;
    }

    public void setInvokeTarget(String invokeTarget)
    {
        this.invokeTarget = invokeTarget;
    }


    public String getCronExpression()
    {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression)
    {
        this.cronExpression = cronExpression;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getNextValidTime()
    {
        if (StringUtils.isNotEmpty(cronExpression))
        {
            try
            {
                CronExpression cron = new CronExpression(cronExpression);
                return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
            }
            catch (ParseException e)
            {
                throw new IllegalArgumentException(e.getMessage());
            }
        }
        return null;
    }

    public String getMisfirePolicy()
    {
        return misfirePolicy;
    }

    public void setMisfirePolicy(String misfirePolicy)
    {
        this.misfirePolicy = misfirePolicy;
    }

    public String getConcurrent()
    {
        return concurrent;
    }

    public void setConcurrent(String concurrent)
    {
        this.concurrent = concurrent;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

}
